/**
 * 
 */
package myTeam.timeShop.controller;

import myTeam.timeShop.bean.TbUser;
import myTeam.timeShop.service.CarouselService;
import myTeam.timeShop.service.SystemService;
import myTeam.timeShop.service.UserService;
import myTeam.timeShop.util.MyMapBuilder;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @author jiangjintai
 *
 */
@RequestMapping("/client/commen")
@Controller
@Api(description="注册版块", value = "注册版块")
public class RegisterController {
	@Autowired
	CarouselService carouselService;
	@Autowired
	UserService userService;
	@Autowired
	SystemService systemService;
	/**
 	 * 用户注册
 	 * jiangjintai
 	 * 2016年3月25日
 	 * @param userAccount
 	 * @param userPassword
 	 * @return
 	 */
 	@ResponseBody
 	@RequestMapping("/register")
	@ApiOperation(value = "用户注册",httpMethod="GET")
 	public String register(
 			@ApiParam(value="用户账户",name="userAccount",required=true)@RequestParam("userAccount")String userAccount,
 			@ApiParam(value="用户密码",name="userPassword",required=true)@RequestParam("userPassword")String userPassword){
 		if(userAccount.trim()==null||userPassword.trim()==null){
 			return JSON.toJSONString(new MyMapBuilder(0, "账户与密码不能为空").build());
 		}else{
 			if(userService.isExistByUserAccount(userAccount)){
 				return JSON.toJSONString(new MyMapBuilder(0, "对不起该账户已经存在").build());
 			}else{
 				userService.doSomeThingForUserRegister(userAccount,userPassword);
 				return JSON.toJSONString(new MyMapBuilder(1, "注册成功").build());
 			}
 		}
 	}
 
}
